﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 批量改扩展名
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Exchange_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(path.Text))
            { MessageBox.Show("所选路径不存在！"); return; }
            if (string.IsNullOrEmpty(originExt.Text) || string.IsNullOrEmpty(replaceExt.Text))
            { MessageBox.Show("扩展名不为空！"); return; }
            string[] files = Directory.GetFiles(path.Text, "*", SearchOption.AllDirectories);
            FileInfo fileInfo;
            foreach (string file in files)
            {
                if (Path.GetExtension(file) == "." + originExt.Text)
                {
                    fileInfo = new FileInfo(file);
                    fileInfo.MoveTo(Path.ChangeExtension(file, "." + replaceExt.Text));
                }
            }
            MessageBox.Show("修改成功！");
        }

        private void browser_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                path.Text = dialog.SelectedPath;
            }
        }
    }
}
